<#assign content>
<input type="hidden" id="machid" name="machid" value="${machid}">
<div class="right_col" role="main">
    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h3>机台</h3>
            </div>
            <div class="title_right"></div>
        </div>
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_content">
                    <#--机台信息显示-->
                        <div class="alert alert-info alert-dismissible fade in" role="alert">
                            <strong>机台名：${sMachine.name}&nbsp&nbsp摆放地址：${sMachine.address}&nbsp&nbsp经度：${sMachine.latitude}&nbsp&nbsp纬度：${sMachine.longitude}&nbsp&nbsp设备名称：${sDevice.name}</strong>
                        </div>
                    <#--大块部分-->
                        <div class="x_content">
                            <div class="" role="tabpanel" data-example-id="togglable-tabs">
                                <ul id="myTab" class="nav nav-tabs bar_tabs" role="tablist">
                                    <li role="presentation" class="active">
                                        <a href="#tab_content1" id="home-tab" role="tab" data-toggle="tab"
                                           aria-expanded="true">机台参数</a>
                                    </li>
                                    <li role="presentation" class="">
                                        <a href="#tab_content2" role="tab" id="profile-tab" data-toggle="tab"
                                           aria-expanded="false">机台菜单</a>
                                    </li>
                                    <li role="presentation" class="">
                                        <a href="#tab_content3" role="tab" id="profile-tab2" data-toggle="tab"
                                           aria-expanded="false">机台原料</a>
                                    </li>
                                </ul>
                                <div id="myTabContent" class="tab-content">
                                    <div role="tabpanel" class="tab-pane fade active in" id="tab_content1"
                                         aria-labelledby="home-tab">
                                        <div id="machineTechContent">
                                            <#if sMachineTechList?exists && sMachineTechList?size gt 0>
                                                <#list sMachineTechList as sMachineTechList>
                                                    <div class="col-md-4 col-sm-4 col-xs-12 profile_details">
                                                        <div class="well profile_view" style="width: 100%">
                                                            <div class="col-sm-12">
                                                                <p><strong>参数标识：<#if sMachineTechList.tkey?exists>${sMachineTechList.tkey}</#if></strong></p>
                                                                <p><strong>当前值：<#if sMachineTechList.cval?exists>${sMachineTechList.cval}</#if></strong></p>
                                                                <p><strong>最小值：<#if sMachineTechList.minval?exists>${sMachineTechList.minval}</#if></strong></p>
                                                                <p><strong>最大值：<#if sMachineTechList.maxval?exists>${sMachineTechList.maxval}</#if></strong></p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </#list>
                                            </#if>
                                        </div>
                                    </div>
                                    <div role="tabpanel" class="tab-pane fade" id="tab_content2"
                                         aria-labelledby="profile-tab">
                                        <div class="x_title">
                                            <ul class="nav navbar-right panel_toolbox">
                                                <li><a id="machineMenuAdd"><i class="fa fa-plus-circle"></i></a></li>
                                                </li>
                                            </ul>
                                            <div class="clearfix"></div>
                                        </div>

                                        <div id="machineMenuContent">
                                            <#if sMachineMenuList?exists && sMachineMenuList?size gt 0>
                                                <#list sMachineMenuList as sMachineMenuList>
                                                    <div class="col-md-4 col-sm-4 col-xs-12 profile_details">
                                                        <div class="well profile_view" style="width: 100%">
                                                            <div class="col-sm-12">
                                                                <p><strong>产品：${sMachineMenuList.productname}</strong>
                                                                </p>
                                                                <p>
                                                                    <strong>产品描述：${sMachineMenuList.description}</strong>
                                                                </p>
                                                                <#if sMachineMenuList.price?exists>
                                                                    <#assign price = MoneyTag.priceToString(sMachineMenuList.price) />
                                                                <#else>
                                                                    <#assign price = 0 />
                                                                </#if>
                                                                <p><strong>原价：${price}</strong></p>
                                                                <#if sMachineMenuList.cprice?exists>
                                                                    <#assign cprice = MoneyTag.priceToString(sMachineMenuList.cprice) />
                                                                <#else>
                                                                    <#assign cprice = 0 />
                                                                </#if>
                                                                <p><strong>当前价：${cprice}</strong></p>
                                                                <p><strong>库存量：${sMachineMenuList.maxcup}</strong></p>
                                                            </div>
                                                            <div class="col-xs-12 bottom text-center">
                                                                <div class="col-xs-12 col-sm-12 emphasis">
                                                                    <button onclick="$.editMachineMenu(${sMachineMenuList.id})"
                                                                            type="button"
                                                                            class="btn btn-success btn-xs"><i
                                                                            class="fa fa-pencil"></i>修改
                                                                    </button>
                                                                    <button onclick="$.deleteMachineMenu(${sMachineMenuList.id},${sMachineMenuList.pid},${sMachineMenuList.machid})"
                                                                            type="button" class="btn btn-danger btn-xs">
                                                                        <i class="fa fa-trash-o"></i>删除
                                                                    </button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </#list>
                                            </#if>
                                        </div>
                                    </div>
                                    <div role="tabpanel" class="tab-pane fade" id="tab_content3"
                                         aria-labelledby="profile-tab">
                                        <div class="clearfix"></div>
                                        <div id="machineMaterialContent">
                                            <#if machineMaterialList?exists && machineMaterialList?size gt 0>
                                                <#list machineMaterialList as machineMaterialList>
                                                    <div class="col-md-4 col-sm-4 col-xs-12 profile_details">
                                                        <div class="well profile_view" style="width: 100%">
                                                            <div class="col-sm-12">
                                                                <p>
                                                                    <strong>原料：${machineMaterialList.materialname}</strong>
                                                                </p>
                                                                <p><strong>单位：${machineMaterialList.unit}</strong></p>
                                                                <p><strong>当前数：${machineMaterialList.amount}</strong>
                                                                </p>
                                                                <p><strong>警告值：${machineMaterialList.warning}</strong>
                                                                </p>
                                                            </div>
                                                            <div class="col-xs-12 bottom text-center">
                                                                <div class="col-xs-12 col-sm-12 emphasis">
                                                                    <button onclick="$.editMachineMaterial(${machineMaterialList.id})"
                                                                            type="button"
                                                                            class="btn btn-success btn-xs"><i
                                                                            class="fa fa-pencil"></i>修改
                                                                    </button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </#list>
                                            </#if>
                                        </div>
                                        <div class="x_content">
                                        <#-- 分割线 -->
                                            <div style="border-top: 2px solid #E6E9ED; margin: 0px 1% 20px 1%;"></div>
                                        <#-- 配方小块 -->
                                            <#if machineBasicsList?exists && machineBasicsList?size gt 0>
                                                <#list machineBasicsList as machineBasicsList>
                                                    <div class="col-md-4 col-sm-4 col-xs-12 profile_details">
                                                        <div class="well profile_view" style="width: 100%">
                                                            <div class="col-sm-12">
                                                                <p><strong>配方名：${machineBasicsList.materialname}</strong>
                                                                </p>
                                                                <p><strong>配方单位：${machineBasicsList.unit}</strong>
                                                                </p>
                                                                <p><strong>当前数：${machineBasicsList.amount}</strong>
                                                                </p>
                                                                <p><strong>警告值：${machineBasicsList.warning}</strong>
                                                                </p>
                                                            </div>
                                                            <div class="col-xs-12 bottom text-center">
                                                                <div class="col-xs-12 col-sm-12 emphasis">
                                                                    <button onclick="$.editMachineMaterial(${machineBasicsList.id})"
                                                                            type="button"
                                                                            class="btn btn-success btn-xs"><i
                                                                            class="fa fa-pencil"></i>修改
                                                                    </button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </#list>
                                            </#if>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</#assign>
<#include "../_inc/layout.ftl" />

<#--机台菜单新增-->
<div class="modal fade" id="machineMenuAddModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">机台菜单新增</h4>
            </div>
            <form id="machineMenuAddForm" method="post" novalidate class="form-horizontal form-label-left">
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">产品<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <select name="pid" id="addproduct" class="form-control col-md-6" required>
                                <option value="">---请选择---</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">当前价<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="addcprice" name="addcprice" data-validate-length-range="5,12"
                                   placeholder="请输入当前价" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="saveMachineMenu" type="button" class="btn btn-success">保存</button>
                        <button class="btn btn-primary" type="reset">重置</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<#--机台菜单修改-->
<div class="modal fade" id="machineMenuEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">机台菜单修改</h4>
            </div>
            <form id="machineMenuEditForm" method="post" novalidate class="form-horizontal form-label-left">
                <input type="hidden" id="edit_machineid" name="machineid">
                <input type="hidden" id="edit_machinemenuid" name="machinemenuid">
                <div class="modal-body">
                </div>
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">当前价<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="editcprice" name="editcprice" data-validate-length-range="5,12"
                                   placeholder="请输入当前价" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="saveEditMachineMenu" type="button" class="btn btn-success">保存</button>
                        <button class="btn btn-primary" type="reset">重置</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<#--机台原料修改-->
<div class="modal fade" id="machineMaterialEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">机台原料修改</h4>
            </div>
            <form id="machineMaterialEditForm" method="post" novalidate class="form-horizontal form-label-left">
                <input type="hidden" id="edit_machineid" name="machineid">
                <input type="hidden" id="edit_machinematerialid" name="machinematerialid">
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">当前值<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="editamount" name="editamount" data-validate-length-range="5,12"
                                   placeholder="请输入当前值" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                </div>
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">警告值<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="editwarning" name="editwarning" data-validate-length-range="5,12"
                                   placeholder="请输入警告值" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="saveEditMachineMaterial" type="button" class="btn btn-success">保存</button>
                        <button class="btn btn-primary" type="reset">重置</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<#--机台菜单删除-->
<div class="modal fade" id="machineMenuDeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">机台参数删除</h4>
            </div>
            <form id="machineMenuDeleteForm" method="post" novalidate class="form-horizontal form-label-left">
                <input type="hidden" id="delete_machineMenuid" name="id">
                <input type="hidden" id="delete_machineMenupid" name="pid">
                <input type="hidden" id="delete_machineid" name="machineid">
                <div class="modal-body">
                    <div class="item form-group">
                        <div class="col-md-10">
                            <span id="machineMenuDeleteMessage"></span>
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="deleteMachineMenuInfo" type="button" class="btn btn-success">确定</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script>

    $(document).ready(function () {

        // 窗体关闭清空页面
        $('#machineMenuAddModal').on('hide.bs.modal', function () {
            $('#machineMenuAddForm')[0].reset();
        });

        // 窗体关闭清空页面
        $('#machineMenuEditModal').on('hide.bs.modal', function () {
            $('#machineMenuEditForm')[0].reset();
        });

        // 窗体关闭清空页面
        $('#machineMaterialEditModal').on('hide.bs.modal', function () {
            $('#machineMaterialEditForm')[0].reset();
        });

        // 机台菜单新增
        $('#machineMenuAdd').on('click', function () {
            var param = {};
            param.machid = $('#machid').val();
            $.ajax({
                type: 'POST',
                url: '/machinemenu_add.do',
                cache: false,
                dataType: 'json',
                data: param,
                success: function (result) {
                    if (result.success) {
                        $('#addproduct').html(result.body.sProductList);
                        $('#machineMenuAddModal').modal({
                            keyboard: true
                        });
                    }
                    else {
                        $.promptModal('${warning}', result.body.msg, result.logout);
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        });

        // 机台菜单提交保存
        $('#saveMachineMenu').on('click', function () {
            if (validator.checkAll($('#machineMenuAddForm'))) {
                var param = {};
                param.action = 'do';
                param.machid = $('#machid').val();
                param.pid = $('#addproduct').val();
                param.cprice = $('#addcprice').val();
                $('#machineMenuAddForm')[0].reset();
                $('#machineMenuAddModal').modal('hide');
                $.ajax({
                    type: 'POST',
                    url: '/machinemenu_add.do',
                    cache: false,
                    dataType: 'json',
                    data: param,
                    success: function (result) {
                        if (result.success) {
                            var params = {};
                            params.id = $('#machid').val();
                            $.submitFormPost('/machine_detail.do', params, 'POST');
                        }
                        else {
                            $.promptModal('${warning}', result.msg, result.logout);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.promptModal('${warning}', '${systemException}', false);
                    }
                });
            }
        });

        // 机台菜单修改
        $.editMachineMenu = function (id) {
            var param = {};
            param.action = 'edit';
            param.id = id;
            $.ajax({
                type: 'POST',
                url: '/machinemenu_edit.do',
                cache: false,
                dataType: 'json',
                data: param,
                success: function (result) {
                    if (result.success) {
                        $('#edit_machinemenuid').val(result.body.sMachineMenu.id);
                        $('#editcprice').val(priceUtil.Price.toPriceString((result.body.sMachineMenu.cprice) * 1));
                        $('#machineMenuEditModal').modal({
                            keyboard: true
                        });
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        };

        // 机台菜单保存修改
        $('#saveEditMachineMenu').on('click', function () {
            if (validator.checkAll($('#machineMenuEditForm'))) {
                var param = {};
                param.action = 'doEdit';
                param.machinemenuid = $('#edit_machinemenuid').val();
                param.cprice = $('#editcprice').val();
                $('#machineMenuEditForm')[0].reset();
                $('#machineMenuEditModal').modal('hide');
                $.ajax({
                    type: 'POST',
                    url: '/machinemenu_edit.do',
                    cache: false,
                    dataType: 'json',
                    data: param,
                    success: function (result) {
                        if (result.success) {
                            var params = {};
                            params.id = $('#machid').val();
                            $.submitFormPost('/machine_detail.do', params, 'POST');
                        }
                        else {
                            $.promptModal('${warning}', result.msg, result.logout);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.promptModal('${warning}', '${systemException}', false);
                    }
                });
            }
        });

        // 机台原料修改开启
        $.editMachineMaterial = function (id) {
            var param = {};
            param.action = 'edit';
            param.id = id;
            $.ajax({
                type: 'POST',
                url: '/machinematerial_edit.do',
                cache: false,
                dataType: 'json',
                data: param,
                success: function (result) {
                    if (result.success) {
                        $('#edit_machineid').val(result.body.sMachineMaterial.machid);
                        $('#edit_machinematerialid').val(result.body.sMachineMaterial.id);
                        $('#editwarning').val(result.body.sMachineMaterial.warning);
                        $('#editamount').val(result.body.sMachineMaterial.amount);
                        $('#machineMaterialEditModal').modal({
                            keyboard: true
                        });
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        };

        // 机台原料保存修改
        $('#saveEditMachineMaterial').on('click', function () {
            if (validator.checkAll($('#machineMaterialEditForm'))) {
                var param = {};
                param.action = 'doEdit';
                param.machinematerialid = $('#edit_machinematerialid').val();
                param.mid = $('#editmid').val();
                param.warning = $('#editwarning').val();
                param.amount = $('#editamount').val();
                $('#machineMaterialEditForm')[0].reset();
                $('#machineMaterialEditModal').modal('hide');
                $.ajax({
                    type: 'POST',
                    url: '/machinematerial_edit.do',
                    cache: false,
                    dataType: 'json',
                    data: param,
                    success: function (result) {
                        if (result.success) {
                            var params = {};
                            params.id = $('#edit_machineid').val();
                            $.submitFormPost('/machine_detail.do', params, 'POST');
                        }
                        else {
                            $.promptModal('${warning}', result.msg, result.logout);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.promptModal('${warning}', '${systemException}', false);
                    }
                });
            }
        });

        // 机台菜单删除
        $.deleteMachineMenu = function (id, pid, machid) {
            $('#delete_machineMenuid').val(id);
            $('#delete_machineMenupid').val(pid);
            $('#delete_machineid').val(machid);
            $('#machineMenuDeleteMessage').html('确定删除该产品？');
            $('#machineMenuDeleteModal').modal({
                keyboard: true
            });
        };

        // 机台菜单保存删除
        $('#deleteMachineMenuInfo').on('click', function () {
            var param = {};
            param.action = 'doDelete';
            param.id = $('#delete_machineMenuid').val();
            param.pid = $('#delete_machineMenupid').val();
            param.machid = $('#delete_machineid').val();
            $('#machineMenuDeleteModal').modal('hide');
            $.ajax({
                type: 'POST',
                url: '/machinemenu_edit.do',
                cache: false,
                dataType: 'json',
                data: param,
                success: function (result) {
                    if (result.success) {
                        var params = {};
                        params.id = $('#delete_machineid').val();
                        $.submitFormPost('/machine_detail.do', params, 'POST');
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        });
    });
</script>

